﻿@page "/useraccounts/details"

@using Microsoft.EntityFrameworkCore
@using BlazorAppAuth.Models
@inject IDbContextFactory<BlazorAppAuth.Data.BlazorAppAuthContext> DbFactory
@inject NavigationManager NavigationManager

<PageTitle>Details</PageTitle>

<h1>Details</h1>

<div>
    <h4>UserAccount</h4>
    <hr />
    @if (useraccount is null)
    {
        <p><em>Loading...</em></p>
    }
    else {
        <dl class="row">
            <dt class="col-sm-2">Name</dt>
            <dd class="col-sm-10">@useraccount.Name</dd>
            <dt class="col-sm-2">Password</dt>
            <dd class="col-sm-10">@useraccount.Password</dd>
            <dt class="col-sm-2">Role</dt>
            <dd class="col-sm-10">@useraccount.Role</dd>
        </dl>
        <div>
            <a href="@($"/useraccounts/edit?id={useraccount.Id}")">Edit</a> |
            <a href="@($"/useraccounts")">Back to List</a>
        </div>
    }
</div>

@code {
    UserAccount? useraccount;

    [SupplyParameterFromQuery]
    public int Id { get; set; }

    protected override async Task OnInitializedAsync()
    {
        using var context = DbFactory.CreateDbContext();
        useraccount = await context.UserAccount.FirstOrDefaultAsync(m => m.Id == Id);

        if (useraccount is null)
        {
            NavigationManager.NavigateTo("notfound");
        }
    }
}
